package controller

import (
	"audio/utils"
	"github.com/gin-gonic/gin"
	"log"
)

func Callback() gin.HandlerFunc {
	return func(c *gin.Context) {
		timestamp := c.DefaultQuery("timestamp", "")
		nonce := c.DefaultQuery("nonce", "")
		echostr := c.DefaultQuery("echostr", "")
		signature := c.DefaultQuery("signature", "")

		if len(nonce) > 0 && utils.CheckSignature(signature, timestamp, nonce) {
			c.String(200, echostr)
		} else {
			log.Fatal("check signature failed")
		}
	}
}
